(function (aopc) {
    aopc.addExpandPage(822, function (get) {
        const Common = get('UtilsCommon', 'Common');
        return {
            expandInit() {
                this.container_view = this.getProperty('container_view');
                this.meeting_score_view = this.getProperty('meeting_score_view');
                this.item_view = this.getViewProperty(this.meeting_score_view, 'item_view');
                this.receiveFunctions.endScore = this.endScore.bind(this);
            },
            endScore(data) {
                if (data.MeetingId === this.pageData.MeetingId) {
                    this.replacePage('/meetingSubjectList.html?MeetingId=' + data.MeetingId);
                }
            },
            expandDataLoad({ data }) {
                if (data.MeetingId) {
                    this.entityData = data;
                    if (data.Scores.length > 0) {
                        this.setSelectScoreItem(0);
                        this.meeting_score_view.setIsVisible(true);
                    }
                    else this.alert('暂无评分项！')
                }
            },
            reload(pageData) {
                this.pageData = pageData;
                this.container_view.reLoad();
            },
            setSelectScoreItem(index) {
                const [left_view, center_view, right_view] = this.meeting_score_view.properties[2].properties;

                this.selectIndex = index;
                this.selectScore = this.entityData.Scores[index];

                this.meeting_score_view.properties[0].properties.forEach(p => {
                    this.setPropertyValue(p, this.selectScore[p.name]);
                });

                this.setIsVisible(left_view.properties[0], this.selectIndex > 0);
                this.setIsVisible(right_view.properties[0], this.selectIndex < this.entityData.Scores.length - 1);

                const { ScoreValue, IsChange, Status, ScoreType } = this.selectScore;

                const enable = Status === 1 && (IsChange || Common.isNullOrEmpty(ScoreValue));

                const [ok_button] = this.meeting_score_view.properties[3].properties;
                this.setIsVisible(ok_button, enable);

                center_view.disabled = !enable;
                center_view.max = ScoreType === 1 ? 100 : 10;

                this.setPropertyValue(center_view, ScoreValue || 0);
                center_view.refresh && center_view.refresh();
            },

            setPrevScore() {
                this.setSelectScoreItem(this.selectIndex - 1);
            },
            setNextScore() {
                this.setSelectScoreItem(this.selectIndex + 1);
            },
            setIsVisible(p, v) {
                p.isVisible = v;
                p.setIsVisible && p.setIsVisible(v);
            },
            setPropertyValue(p, v) {
                p.value = v;
                p.setValue && p.setValue(v);
            },
            expandSetScoreRecordData({ entityData }) {
                if (!(entityData.ScoreValue > 0)) {
                    this.alert('请先进行评分！');
                    return false;
                }
                entityData.ScoreId = this.selectScore.ScoreId;
                entityData.MeetingId = this.pageData.MeetingId;
                entityData.UserName = this.selectScore.IsRealName ? this.entityData.UserName : '';
                this.editEntityData = entityData;
                return entityData;
            },
            saveRecordCallback({ props }) {
                this.alertSuccess('提交成功', () => {
                    if (this.selectScore.IsChange === 0) {
                        this.selectScore.disabled = true;
                        props.property.setIsVisible(false);
                    }
                    this.selectScore.ScoreValue = this.editEntityData.ScoreValue;
                });
            }
        }
    });
})(window.aopc);